    <div id="featuredbar">
        <div class="topbox">&nbsp
            <h2>Featuring...</h2>
            <p>Click to view details and leave an entry</p>
        </div>
        <ul>
<?php
    function featuringdateformat($date)
    {
        if ($date == "0000-00-00 00:00:00") {
            return "";
        } else {
            return date('d/m/Y', strtotime(str_replace("&", "&amp;", $date)))."<br />";
        }
    }
    function lastNameConvert($str1)
    {
        if (empty($str1) || strlen($str1) == 0) {
            return "";
        }
        $str2 = "";
        $str1 = strtolower($str1);
        $loop = true;
        $i = 0;
        while ($loop) {
            if (strlen($str1) == $i) {
                $loop = false;
            }
            if (($str1[$i] == "-" || $str1[$i] == " ") && $i+1 <= strlen($str1)) {
                $str2 = $str2 . $str1[$i];
                $i++;
                $str2 = $str2 . $str1[$i];
            } else {		
                $str2 = $str2 . $str1[$i];		
            }
            $i++;
        }
        return ucfirst($str2);
    }
    function formatblurbdetails($b, $person) {
        $limit = 60; 
        $b = stripslashes($b);
        if (strlen($b) == 0) {
            $b = '';
        }
        $end = strrpos(substr($b, 0, $limit), ' ');
        $b = substr($b, 0, $end);
        return '<a href="remembrance.php?personid=' . $person . '">' . $b . '...</a>';
    }
    $query = "
SELECT
    FeaturingPerson.Blurb,
    FeaturingPerson.PersonID,
    FeaturingPerson.Position,
    Person.DeathDate,
    Person.Surname,
    Person.FirstNames
FROM
    FeaturingPerson
        LEFT OUTER JOIN Person
             ON FeaturingPerson.PersonID = Person.ID
WHERE
    Position BETWEEN 0 AND 3
ORDER BY
    Position ASC
";

    // Perform Query
    $result = mysql_query($query, $link);
    // Check result
    // This shows the actual query sent to MySQL, and the error. Useful for debugging.
    if (!$result) {
        $message  = 'Invalid query: ' . mysql_error() . "\n";
        $message .= 'Whole query: ' . $query;
        die($message);
    }
    $num_rows = mysql_num_rows($result);
    $count = 0;
    while ($row = mysql_fetch_assoc($result)) {
        $count++;
        if ($count == $num_rows) {
            echo "<li class=\"bottomitem\">";
        } else if($count == 1) {
            echo "<li class=\"topitem\">";
        } else {
            echo "<li>";
        }
        $image = "/home/amemoryt/public_html/images/featuring/".$row['PersonID'].".jpg";
        if (file_exists($image)) {
            echo "<a href=\"remembrance.php?personid=".$row['PersonID']."\"><img alt=\"\" style=\"width:115px;\" src=\"http://amemorytree.co.nz/images/featuring/".$row['PersonID'].".jpg\"/></a>";
        } else {
            echo "<a href=\"remembrance.php?personid=".$row['PersonID']."\"><img src=\"images/assets/placeholderphoto.gif\" alt=\"\" /></a>";
        }     
        echo "<h4><a href=\"remembrance.php?personid=".$row['PersonID']."\">".str_replace("&", "&amp;", $row['FirstNames'])." ".lastNameConvert($row['Surname'])."</a></h4>";
        echo "<p>".featuringdateformat($row['DeathDate']).formatblurbdetails($row['Blurb'], $row['PersonID'])."</p>";
        echo "</li>";
    }
?>   
        </ul>
        <div class="bottombox">
            <ul>
<?php
    $query = "SELECT `FeaturingPerson`.Blurb, `FeaturingPerson`.PersonID, `FeaturingPerson`.Position, Person.DeathDate, Person.Surname, Person.FirstNames FROM `FeaturingPerson` left join `Person` on `FeaturingPerson`.PersonID = Person.ID Where `Position` Between 4 and 9 order by `Position` ASC";
    // Perform Query
    $result = mysql_query($query, $link);
    // Check result
    // This shows the actual query sent to MySQL, and the error. Useful for debugging.
    if (!$result) {
        $message  = 'Invalid query: ' . mysql_error() . "\n";
        $message .= 'Whole query: ' . $query;
        die($message);
    }
    while ($row = mysql_fetch_assoc($result)) {
        echo "<li><a href=\"remembrance.php?personid=".$row['PersonID']."\">".str_replace("&", "&amp;", $row['FirstNames'])." ".lastNameConvert($row['Surname'])."</a></li>";
    }
?>   
            </ul>
            <a href="featuringhistory.php" title="Previously featured">Previously featured</a>
        </div> 
    </div>
